﻿using System;
using System.Diagnostics.Contracts;

namespace MathService.Attributes
{
    [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
    public sealed class ElementNameAttribute : Attribute
    {
        private string f_Name;

        public string Name { get { return f_Name; } set { f_Name = value; } }

        public ElementNameAttribute(string Name)
        {
            f_Name = Name;
        }

        public override string ToString()
        {
            if(Name == null) throw new FormatException();
            return Name;
        }

        public override int GetHashCode()
        {
            //if(f_Name == null)
            //    throw new ArgumentNullException();
            //Contract.EndContractBlock();
            return f_Name.GetHashCode() ^ typeof(ElementNameAttribute).GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var A = obj as ElementNameAttribute;
            if(A == null) return base.Equals(obj);
            return A.f_Name == f_Name;
        }

        public static implicit operator string(ElementNameAttribute A)
        {
            Contract.Requires(A != null);
            return A.f_Name;
        }
    }
}
